package DbUtil;

import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Statement;
import java.util.ArrayList;
import java.util.List;

import dto.Item;


public class DbUtil {

	public static List getItems(String sql){
		List list = new ArrayList();
    	String sDriveName_="com.microsoft.jdbc.sqlserver.SQLServerDriver";
    	//String sUrl_="jdbc:microsoft:sqlserver://21.16.121.117:1433;databasename=CQHist430";
    	String sUrl_="jdbc:microsoft:sqlserver://127.0.0.1:1433;databasename=CQHist430";
    	String sUser_="sa"; 
        String sPassword_="sa"; 
        try {
			Class.forName(sDriveName_).newInstance();
			Connection mvConn= DriverManager.getConnection(sUrl_,sUser_,sPassword_);
			Statement st = mvConn.createStatement();
			ResultSet rs = st.executeQuery(sql);
			while(rs.next()){
				Item item = new Item();
				
				item.setId(rs.getString("branchno"));
				item.setName(rs.getString("branchname"));
				item.setF_id(rs.getString("subcenterno"));
				list.add(item);
			}
			rs.close();
			st.close();
			mvConn.close();
		} catch (InstantiationException e) {

			e.printStackTrace();
		} catch (IllegalAccessException e) {
			e.printStackTrace();
		} catch (ClassNotFoundException e) {

			e.printStackTrace();
		}            
		catch (SQLException e) {
			e.printStackTrace();
		}	
        return list;
	}
}
